package com.tc.juc.pack08;

import lombok.extern.slf4j.Slf4j;

import java.util.List;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;

/**
 * @Auther: tianchao
 * @Date: 2021/10/17 10:40
 * @Description:
 */
@Slf4j
public class TestShutDown {
    public static void main(String[] args) {
        ExecutorService pool = Executors.newFixedThreadPool(2);
        Future<Integer> result1 = pool.submit(() -> {
            log.info("task1 running...");
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            log.info("task1 finish...");
            return 1;
        });
        Future<Integer> result2 = pool.submit(() -> {
            log.info("task2 running...");
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            log.info("task2 finish...");
            return 2;
        });
        Future<Integer> result3 = pool.submit(() -> {
            log.info("task3 running...");
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            log.info("task3 finish...");
            return 3;
        });
        log.info("shutdown....");
        // pool.shutdown();
        List<Runnable> runnables = pool.shutdownNow();
        for (Runnable runnable : runnables) {
            runnable.run();
        }
        Future<Integer> result4 = pool.submit(() -> {
            log.info("task4 running...");
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            log.info("task4 finish...");
            return 4;
        });

    }
}
